<template>
	<view>
		<u-popup :show="show" @close="close" @open="open" closeable>
			<view>
				<view class="popuptitle">
					确认到达
				</view>
				<u--form labelPosition="left" ref="uForm">
					<u-form-item label="照片" borderBottom ref="item1">
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="10"></u-upload>
					</u-form-item>
				</u--form>
				<bottombox>
					<u-button type="error" :loading="loading" text="确认到达" @click="onarrival"></u-button>
				</bottombox>

			</view>
		</u-popup>
		<!-- <u-button @click="show = true">打开</u-button> -->
		<zmodal ref="zmodal"></zmodal>
	</view>
</template>
<script>
import { upload } from "@/utils/oss.js";
import {

		arrival
	} from "@/api/routePlanningInfo.js";
export default {
	props: {
		query: {
				typeof: Object,
				default: () => {
					return {};
				},
			},
		},
	data() {
		return {
			show: false,
			fileList1: [],
			loading: false
		}
	},
	methods: {
		open() {
			this.show = true
			// console.log('open');
		},
		close() {
			this.show = false
			// console.log('close');
		},
		// 删除图片
		deletePic(event) {
			this[`fileList${event.name}`].splice(event.index, 1);
		},
		// 新增图片
		async afterRead(event) {
			// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
			let lists = [].concat(event.file);
			let fileListLen = this[`fileList${event.name}`].length;
			lists.map((item) => {
				this[`fileList${event.name}`].push({
					...item,
					status: "uploading",
					message: "上传中",
				});
			});
			for (let i = 0; i < lists.length; i++) {
				const result = await this.uploadFilePromise(lists[i].url);
				let item = this[`fileList${event.name}`][fileListLen];
				this[`fileList${event.name}`].splice(
					fileListLen,
					1,
					Object.assign(item, {
						status: "success",
						message: "",
						url: result,
					})
				);
				fileListLen++;
			}
		},
		uploadFilePromise(url) {
			return new Promise((resolve, reject) => {
				upload(url).then(res => {
					console.log(res, 123);
					resolve(res)
				})
				// let a = uni.uploadFile({
				// 	url: "http://192.168.2.21:7001/upload", // 仅为示例，非真实的接口地址
				// 	filePath: url,
				// 	name: "file",
				// 	formData: {
				// 		user: "test",
				// 	},
				// 	success: (res) => {
				// 		setTimeout(() => {
				// 			resolve(res.data.data);
				// 		}, 1000);
				// 	},
				// });
			});
		},
		onarrival() {
			this.$refs.zmodal.init({
				content: "确认到达？",
				confirm: async () => {
					await arrival(this.query.id, this.fileList1)
					this.$z.back();
				}
			})
		},
	}
}
</script>
<style lang="scss" scoped>
.popuptitle {
	height: 100rpx;
	line-height: 100rpx;
	font-size: 32rpx;
	font-weight: bold;
	padding-left: 30rpx;
	position: relative;
	margin-bottom: 20rpx;

	&::after {
		content: '';
		position: absolute;
		left: 30rpx;
		right: 30rpx;
		bottom: 0;
		height: 1px;
		background-color: #eee;
	}
}
</style>
